#!/usr/bin/env python
# coding=utf-8
"""
# @Created on : 2016/06/19 22:04
# @Author     : ldf (ldf@eehello.com)
# @Link       : http://www.eehello.com
# @Version    : 
# 本程序在python2.7下测试通过
"""
from django import views

'''
import socket

def handle_request(client):
    buf = client.recv(1024)
    client.send("HTTP/1.1 200 OK\r\n\r\n")
    client.send("Hello, seven")


def main():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('localhost',8888))
    sock.listen(5)

    while 1:
        connection, address = sock.accept()
        handle_request(connection)
        connection.close()

if __name__ == '__main__':
    main()
'''

from wsgiref.simple_server import make_server

def runserver(environ, start_response):

    start_response('200 OK',[('content-Type', 'text/html')])

    #函数
    def abc():
        return '<h1>abc</h1><p><h1>test</h1>'


    #获取用户的URL
    userurl = environ['PATH_INFO']


    if userurl == '/index':
        return '<h1>index</h1>'
    elif userurl == '/login':
        return '<h1>login</h1>'
    elif userurl == '/logout':
        return '<h1>logout</h1>'
    elif userurl =='/':
        return '<h1>/</h1>'
    elif userurl == '/abc':
        return abc()
    else:
        return '<h1>404</h1>'






if __name__ == '__main__':
   httpd = make_server('',10101, runserver)
   print 'serving http on port 10101'
   httpd.serve_forever()






'''
urls

"""
    url(r'^index', index),
    url(r'^login', login),
    url(r'^list/(?P<name>\d*)/(?P<id>\d*)', list),
    url(r'^list/(?P<name>\d*)', list,{'id':10}),
    
    url(r'^', root),
    """
    #url --- file
    #file -- url>Function
    
    url(r'^web', include(web.urls)),
    url(r'^ad', include(ad.urls)),
    
    
views

def root(request):
    with open('template/root.html','r') as fr:
        root = fr.read()
    return HttpResponse(root)


def index(request):
    
    return HttpResponse('index')


def login(request):
    
    return HttpResponse('login')

def list(request,name,id):
    print name,'123',id
    return HttpResponse('list')

'''
    
    
    